package com.ruoyi.web.controller.train;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.PracticeCadetMasterSkill;
import com.ruoyi.system.domain.PracticeCadetMasterSkillCount;
import com.ruoyi.system.service.IPracticeCadetMasterSkillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 实践掌握技能Controller
 *
 * @author dp
 * @date 2023-12-02
 */
@Api(tags = {"实践掌握技能"})
@RestController
@RequestMapping("/system/skill")
public class PracticeCadetMasterSkillController extends BaseController {
    @Autowired
    private IPracticeCadetMasterSkillService practiceCadetMasterSkillService;
    @Autowired
    TokenService tokenService;

    /**
     * 查询实践掌握技能列表
     */
    @ApiOperation(value = "实践掌握技能列表", notes = "查询实践掌握技能列表详情", tags = {"实践掌握技能管理"})
    //@PreAuthorize("@ss.hasPermi('system:SKILL:list')")
    @GetMapping("/list")
    public TableDataInfo list(PracticeCadetMasterSkill practiceCadetMasterSkill) {
        startPage();
        List<PracticeCadetMasterSkill> list = practiceCadetMasterSkillService.selectPracticeCadetMasterSkillList(practiceCadetMasterSkill);
        return getDataTable(list);
    }

    /**
     * 查询实践掌握技能合计列表
     */
    @ApiOperation(value = "实践掌握技能合计列表", notes = "查询实践掌握技能列表详情", tags = {"实践掌握技能管理"})
    @GetMapping("/countList")
    public TableDataInfo countList(@RequestParam("submitBegin") String submitBegin, @RequestParam("submitEnd") String submitEnd,
                                   @RequestParam("baseId") String baseId,
                                   @RequestParam("masterSkillStatus") String masterSkillStatus) {
        startPage();
        List<PracticeCadetMasterSkillCount> list = practiceCadetMasterSkillService.selectPracticeCadetMasterSkillCount(submitBegin, submitEnd, baseId, masterSkillStatus);
        return getDataTable(list);
    }

    /**
     *  根据条件查询实践掌握技能列表
     * @param submitBegin
     * @param submitEnd
     * @param baseId
     * @param cadetId
     * @param masterSkillStatus
     * @return
     */
    @ApiOperation(value = "实践掌握技能列表", notes = "查询实践掌握技能列表详情", tags = {"实践掌握技能管理"})
    @GetMapping("/getMasterSkillList")
    public TableDataInfo getMasterSkillList(@RequestParam("submitBegin") String submitBegin, @RequestParam("submitEnd") String submitEnd,
                                            @RequestParam("baseId") String baseId, @RequestParam("cadetId") String cadetId,
                                            @RequestParam("masterSkillStatus") String masterSkillStatus) {
        startPage();
        List<PracticeCadetMasterSkill> list = practiceCadetMasterSkillService.getMasterSkillList(submitBegin, submitEnd, baseId, cadetId, masterSkillStatus);
        return getDataTable(list);
    }

    /**
     * 导出实践掌握技能列表
     */
    @ApiOperation(value = "实践掌握技能列表导出", notes = "导出实践掌握技能列表详情", tags = {"实践掌握技能管理"})
    //@PreAuthorize("@ss.hasPermi('system:SKILL:export')")
    @Log(title = "实践掌握技能", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PracticeCadetMasterSkill practiceCadetMasterSkill) {
        List<PracticeCadetMasterSkill> list = practiceCadetMasterSkillService.selectPracticeCadetMasterSkillList(practiceCadetMasterSkill);
        ExcelUtil<PracticeCadetMasterSkill> util = new ExcelUtil<PracticeCadetMasterSkill>(PracticeCadetMasterSkill.class);
        util.exportExcel(response, list, "实践掌握技能数据");
    }

    /**
     * 获取实践掌握技能详细信息
     */
    @ApiOperation(value = "获取实践掌握技能详细信息", notes = "获取实践掌握技能详细信息详情", tags = {"实践掌握技能管理"})
    //@PreAuthorize("@ss.hasPermi('system:SKILL:query')")
    @GetMapping(value = "/{masterSkillId}")
    public AjaxResult getInfo(@PathVariable("masterSkillId") Long masterSkillId) {
        return success(practiceCadetMasterSkillService.selectPracticeCadetMasterSkillByMasterSkillId(masterSkillId));
    }

    /**
     * 新增实践掌握技能
     */
    @ApiOperation(value = "新增实践掌握技能", notes = "新增实践掌握技能详情", tags = {"实践掌握技能管理"})
    //@PreAuthorize("@ss.hasPermi('system:SKILL:add')")
    @Log(title = "实践掌握技能", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(HttpServletRequest request, @RequestBody PracticeCadetMasterSkill practiceCadetMasterSkill) {
        Long userId = tokenService.getLoginUser(request).getUser().getUserId();
        practiceCadetMasterSkillService.completeData(practiceCadetMasterSkill, userId, 1);
        return toAjax(practiceCadetMasterSkillService.insertPracticeCadetMasterSkill(practiceCadetMasterSkill));
    }

    /**
     * 修改实践掌握技能
     */
    @ApiOperation(value = "修改实践掌握技能", notes = "修改实践掌握技能详情", tags = {"实践掌握技能管理"})
    //@PreAuthorize("@ss.hasPermi('system:SKILL:edit')")
    @Log(title = "实践掌握技能", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(HttpServletRequest request, @RequestBody PracticeCadetMasterSkill practiceCadetMasterSkill) {
        Long userId = tokenService.getLoginUser(request).getUser().getUserId();
        practiceCadetMasterSkillService.completeData(practiceCadetMasterSkill, userId, 2);
        return toAjax(practiceCadetMasterSkillService.updatePracticeCadetMasterSkill(practiceCadetMasterSkill));
    }

    /**
     * 删除实践掌握技能
     */
    @ApiOperation(value = "删除实践掌握技能", notes = "删除实践掌握技能详情", tags = {"实践掌握技能管理"})
    //@PreAuthorize("@ss.hasPermi('system:SKILL:remove')")
    @Log(title = "实践掌握技能", businessType = BusinessType.DELETE)
    @DeleteMapping("/{masterSkillIds}")
    public AjaxResult remove(@PathVariable Long[] masterSkillIds) {
        return toAjax(practiceCadetMasterSkillService.deletePracticeCadetMasterSkillByMasterSkillIds(masterSkillIds));
    }
}
